package patterns.chain;

import System.Task.Task;

public class SystemFailureHandler implements EmergencyHandler {
    private EmergencyHandler nextHandler;

    @Override
    public void setNextHandler(EmergencyHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    @Override
    public void handleRequest(String emergencyType, Task task, String details) {
        if ("SYSTEM_FAILURE".equals(emergencyType)) {
            System.out.println("[紧急处理] 系统故障 - 任务: " + task.getTaskId());
            task.addCommand("系统故障: " + details);

            // 停止所有操作
            task.addCommand("系统故障，所有操作已中止");

            // 标记任务为失败
            task.fail("系统故障: " + details);
        } else if (nextHandler != null) {
            nextHandler.handleRequest(emergencyType, task, details);
        }
    }
}
